package cn.edu.cug.cs.gtl.docsrv.dict.exception;


import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.LinkedHashMap;
import java.util.Map;

@ControllerAdvice
public class HandlerException {

    @ResponseBody
    @ExceptionHandler(Exception.class)
    public Map<String, Object> exception(Exception e) {
        Map<String, Object> map = new LinkedHashMap<>();
        map.put("timestamp", System.currentTimeMillis());
        map.put("status", HttpStatus.FORBIDDEN.value());
        map.put("error", HttpStatus.FORBIDDEN.getReasonPhrase());
        map.put("exception", e.getClass());
        map.put("message", e.getMessage());
        return map;
    }
}
